from django.shortcuts import render
from user import serializers
from .models import Phonenum
from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import action
from rest_framework.response import Response
# Create your views here.

class Phonenum1(ModelViewSet):
    serializer_class = serializers.Phonenumser
    queryset = Phonenum.objects.all()
    print('hello world 世界你好')
    @action(detail=False,methods=['POST'])
    def login(self,request):
        phone1 = request.data["phone1"]
        password = request.data["password1"]
        print(phone1)
        data1 = Phonenum.objects.filter(phone=phone1).first()
        print(data1)
        if data1:
            data2 = Phonenum.objects.filter(phone=phone1,password=password).first()
            if data2:
                return Response({"status":200,"msg":"登陆成功"})
            else:
                return Response({"msg":"密码错误"})
        else:
            return Response({"msg":"账号不存在"})



